<?php
namespace Backend\Model;
use Think\Model;

class  AdGameModel extends  Model
{
    protected $_validate = array(
        //array('media_id', 'require', '必须要选择一个主分类！', 1),
        array('game_name', 'require', '游戏物料名称不能为空！', 1),
        array('game_name', '', '游戏物料名称已存在！', 0, 'unique', 3),
        array('game_logo', 'require', '图片不能为空！', 1),
        array('game_describe', 'require', '游戏描述不能为空！', 1),
        array('g_id', 'require', '游戏id不能为空！', 1),
        array('g_id', 'number', '游戏id必须是数字！', 1),


    );

    public function get_adGame($pageSize=10){
        $where = array('user_id' =>$_SESSION['id']);
        $count = $this->alias('a')->where($where)->count();
        $page = new \Think\Page($count, $pageSize);
        // 配置翻页的样式
        $page->setConfig('prev', '上一页');
        $page->setConfig('next', '下一页');
        $data['page'] = $page->show();
        //var_dump($data['page']);exit;
        /************************************** 取数据 ******************************************/

        $data['data'] = $this->alias('a')
            ->field('id,game_name,game_logo,game_describe,g_id,application_channel')
            ->where($where)
            ->order('id desc')
            ->limit($page->firstRow.','.$page->listRows)
            ->select();
        return $data;
    }


    // 添加前
    protected function _before_insert(&$data) {
        $data['user_id'] =$_SESSION['id'];
    }
}